package com.demo.controller;

import com.demo.entity.Product;
import com.demo.entity.ProductRecord;
import com.demo.repository.ProductRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Iterator;

/**
 * Created by liushuang on 2017/6/22.
 */
@RequestMapping(value = "/admin/products")
@RestController
public class ProductController {
    @Autowired
    private ProductRepo productRepo;

    @RequestMapping(value = "", method = RequestMethod.GET)
    public Iterator<Product> getProductList(){
        Iterator<Product> products = productRepo.findAll().iterator();
        return products;
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.POST)
    public Product putProduct(@PathVariable String id, @RequestBody Product product){
        System.out.println(product.getMoney());
        productRepo.save(product);
        return product;
    }
}
